package view;

import java.awt.Color;

import java.awt.event.ActionListener;




import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JLabel;

import javax.swing.JTextField;
/**
 * this class is Graphic user interface of add new item which extends AbstractGUI
 * @author Moran
 *
 */
public class NewItemGUI extends AbstractGUI {
	private JTextField ItemName = null;
	private JLabel nametxt = null;
	private JButton addB = null;
	private JLabel warningMes = null;
	private JTextField price;
	private JTextField discription;
	private JLabel jlabel1;//image label
	private JButton btnChuseFile;
	
	/**
	 * constructor 
	 * this constructor add all the Label, Button,TextField to the Frame
	 */
	public NewItemGUI(){
		getContentPane().add( getItemName());
		getContentPane().add(getNametxt());
		getContentPane().add(getAdd());
		getContentPane().add(getBackButton());
		getContentPane().add(getWarningMes());
		getContentPane().setBackground(Color.LIGHT_GRAY);
		getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Discription:");
		lblNewLabel.setBounds(30, 104, 70, 14);
		getContentPane().add(lblNewLabel);
		
		btnChuseFile = new JButton("Choose File");
		btnChuseFile.setBounds(105, 134, 140, 23);
		getContentPane().add(btnChuseFile);
		
		JLabel lblPicture = new JLabel("Picture:");
		lblPicture.setBounds(30, 138, 46, 14);
		getContentPane().add(lblPicture);
		
		JLabel lblPrice = new JLabel("price:");
		lblPrice.setBounds(30, 370, 70, 14);
		getContentPane().add(lblPrice);
		
		price = new JTextField("");
		price.setColumns(10);
		price.setBounds(105, 365, 307, 25);
		getContentPane().add(price);
		
		discription = new JTextField("");
		discription.setColumns(10);
		discription.setBounds(105, 99, 307, 25);
		getContentPane().add(discription);
		getContentPane().add(getJlabel1());
		this.setTitle("Add Item");
		this.setBounds(500, 170, 484, 540);
		this.setVisible(true);
		this.setResizable(false);
	}
	/** 
	 * Getters and Setters of Label, Button,TextField 
	 */
	public String getPrice() {
		return price.getText();
	}
	public void setPrice(JTextField price) {
		this.price = price;
	}
	public String getDiscription() {
		return discription.getText();
	}
	public void setDiscription(JTextField discription) {
		this.discription = discription;
	}
	public Icon getImage() {
		return this.jlabel1.getIcon() ;//*****
	}
	public JTextField getItemName() {
		if(ItemName == null){
			ItemName = new JTextField("");
			ItemName.setBounds(105, 65, 307, 25);
			ItemName.setColumns(10);	
		}
		return ItemName;
	}
	public String getItemNameText() {
		return ItemName.getText();	
	}
	public JLabel getNametxt() {
		if(nametxt == null){
			nametxt = new JLabel("Item name:");
			nametxt.setBounds(30, 65, 100, 25);
		}
		return nametxt;
	}
	public JButton getAdd() {
		if(addB == null){
			addB = new JButton("Add");
			addB.setBounds(323, 451, 100, 30);
		}
		return addB;
	}
	public JButton getBackButton() {
		if(backButton == null){
			backButton = new JButton("back");
			backButton.setBounds(80, 451, 100, 30);
		}
		return backButton;
	}
	public JLabel getWarningMes() {
		if(warningMes == null){
			warningMes = new JLabel("This area is already exist");
			warningMes.setForeground(Color.RED);
			warningMes.setBounds(184, 415, 170, 25);
			warningMes.setVisible(false);
		}	
		return warningMes;
	}
	/**
	 * set Warning Massage on gui
	 */
	public void setWarningMes(String str) {
		warningMes.setText(str);
		warningMes.setVisible(true);
	}
	public void setWarningMesFalse(){
		warningMes.setVisible(false);
	}
	/**
	 * add to Add button ActionListener
	 * @param listener
	 */
	public void addAddActionListener(ActionListener listener){
		addB.addActionListener(listener);
	}
	/**
	 * add to chose file button ActionListener
	 * @param listener
	 */
	public void chusefileAddActionListener(ActionListener listener){
		btnChuseFile.addActionListener(listener);
	}
	
	private JLabel getJlabel1() {//image label
		if (jlabel1 == null) {
			jlabel1 = new JLabel("");
			jlabel1.setBounds(212, 144, 200, 200);
		}
		return jlabel1;
	}
	public void setJlabel1(ImageIcon format){//image label
		jlabel1.setIcon(format);
	}
	
}
